"""
一些常用的数学计算方法
"""
import math


# 计算两点之间的距离
def get_distance(start, end):
    cx, cy = start
    lx, ly = end
    s = math.sqrt((cx - lx) * (cx - lx) + (cy - ly) * (cy - ly))
    return s


# 计算两点之间的方向角
def get_angle(start, end):
    dx = end[0] - start[0]
    dy = end[1] - start[1]
    if dy < 0:
        if dx > 0:
            angle = -math.atan(dy / dx)
        elif dx < 0:
            angle = math.pi / 2 + math.atan(dx / dy)
        else:
            angle = math.pi / 2
    elif dy > 0:
        if dx > 0:
            angle = 3 * math.pi / 2 + math.atan(dx / dy)
        elif dx < 0:
            angle = math.pi - math.atan(dy / dx)
        else:
            angle = 3 * math.pi / 2
    else:
        if dx > 0:
            angle = 0
        elif dx < 0:
            angle = math.pi
        else:
            angle = -1
    return angle
